|
The most vexing parse is a specific form of syntactic ambiguity resolution in the C++ programming language. The term was used by Scott Meyers in ''Effective STL'' (2001). It is formally defined in section 8.2 of the C++ language standard.〔ISO/IEC (2003). ''ISO/IEC 14882:2003(E): Programming Languages - C++ §8.2 Ambiguity resolution ()''〕 == Example with classes == An example is: The line is ambiguous, since it could be interpreted either as # a variable definition for variable of class , initialized with an anonymous instance of class or # a function declaration for a function which returns an object of type and has a single (unnamed) parameter which is a function returning type (and taking no input). (See Function object#In C and C++) Most programmers expect the first, but the C++ standard requires it to be interpreted as the second. For example, g++ gives the following error message: Clang++ provides a warning: $ clang++ time_keeper.cc timekeeper.cc:14:25: parentheses were disambiguated as a function declaration () TimeKeeper time_keeper(Timer()); timekeeper.cc:14:26: note: add a pair of parentheses to declare a variable TimeKeeper time_keeper(Timer()); timekeeper.cc:15:21: member reference base type 'TimeKeeper (Timer ( *)())' is not a structure or union return time_keeper.get_time(); One way to force the compiler to consider this as a variable definition is to add an extra pair of parentheses: 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Most vexing parse」の詳細全文を読む スポンサード リンク
|